package lew.bing.exp.collection;

import java.util.Stack;

/**
 * Created by 刘国兵 on 2018/9/3.
 */
public class MyStack<T> {

    private static final int MAX = 1024;

    private Object[] arrs = new Object[MAX];

    int top = 0;

    public boolean isEmpty() {
        return top == 0;
    }

    public void put(T t) {
        if (top == MAX) {
            throw new StackOverflowError();
        }
        arrs[top] = t;
        top ++;
    }

    @SuppressWarnings("unchecked")
    public T pop() {
        if (isEmpty()) {
            throw new StackOverflowError();
        }
        top --;
        return (T) arrs[top];
    }

    @SuppressWarnings("unchecked")
    public T peek() {
        if (isEmpty()) {
            return null;
        }
        return (T) arrs[top];
    }



}
